package com.aaa.doctor.service.impl;

import com.aaa.doctor.dao.MedicinesDao;
import com.aaa.doctor.service.MedicinesService;
import com.aaa.doctor.vo.MedicinesVo;
import com.aaa.entity.Medicines;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class MedicinesServiceImpl implements MedicinesService {

    @Autowired
    private MedicinesDao medicinesDao;

    /**
     * 根据条件查询药品信息
     * @param pageCurrent
     * @param pageSize
     * @param medicinesVo
     * @return
     */
    @Override
    public Result<IPage<Medicines>> listMedicinesForPage(Integer pageCurrent, Integer pageSize, MedicinesVo medicinesVo) {
        IPage<Medicines> page = new Page<>(pageCurrent,pageSize);
        QueryWrapper<Medicines> wrapper = new QueryWrapper<>();
        if (StringUtils.hasText(medicinesVo.getKeywords())){
            wrapper.like("keywords",medicinesVo.getKeywords());
        }
        IPage<Medicines> medicinesIPage = medicinesDao.selectPage(page, wrapper);
        return new Result<>(200,"查询药品信息成功",medicinesIPage);
    }
}
